-
Notifications
You must be signed in to change notification settings - Fork 17
Extended Type Functionality and Adapted for newer DTCG format #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
src/utils/lineHeight.ts
Outdated
| export function convertLineHeightPercentageToMultiplier(value: any): number { | ||
| if (typeof value === "number") { | ||
| return value / 100 | ||
| } else if (typeof value === "string") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you have the redundant check for string type if you're going to treat everything like a string anyway?
src/controller/variables.ts
Outdated
| function convertRemToPx(value: any): number { | ||
| if (typeof value === "number") { | ||
| return value * 16 | ||
| } else if (typeof value === "string") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why duplicate the string case for the default vs just having a default?
| } | ||
|
|
||
| // Split by comma to get the first font in the stack | ||
| const firstFont = value.split(",")[0].trim() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a possibility that value.split doesn't have a valid return, which would cause this to crash?
This pull request introduces support for additional token types and improves compatibility with both legacy and modern token formats. It adds handling for
fontSize,borderRadius,lineHeight,letterSpacing,fontFamily, andfontWeighttokens, and ensures that bothtype/valueand$type/$valueproperties are supported. The update also includes utility functions for font and line height conversions and improves robustness in token alias and value handling.This update was prompted to support more token types and kept all previous functionality.
Token Type Support and Handling:
fontSize,borderRadius,lineHeight,letterSpacing,fontFamily,fontWeight) throughout the import pipeline and token type resolution, including mapping to Figma types and value conversions. [1] [2] [3] [4]JsonTokeninterface and related type guards to support both legacy ($type,$value,$extensions) and modern (type,value,extensions) token property formats, ensuring backward compatibility. [1] [2]Utility Functions for Value Conversion:
extractFirstFontFamilyto parse the first font family from a CSS string,mapFontWeightto map numeric font weights to Figma-friendly names, andconvertLineHeightPercentageToMultiplierto convert line height percentages to multipliers. [1] [2] [3]convertRemToPxto convertremvalues to pixel values for font size tokens.Robustness and Error Handling:
valueand$valueproperties, and clarified error messages for missing or unsupported tokens. [1] [2] [3]Dependency Updates:
@figma/plugin-typingsto the latest version and replacednode-sasswithsassin the development dependencies for better compatibility and maintenance. [1] [2]